package com.itheima.service.impl;
import com.itheima.entity.Dept;
import com.itheima.mapper.DeptMapper;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

//业务逻辑处理层
//@Component//程序启动时会创建对象
//@Primary//优先级最高
@Service//逻辑处理类
public class DeptServiceImpl implements DeptService {
//    private DeptDao deptDao = new DeptDaoImpl();
    @Autowired
    private DeptMapper deptMapper;

// 定义一个list方法，返回一个Dept类型的List
    public List<Dept> list()
    {
    // 调用deptMapper的list方法，返回一个Dept类型的List
        return deptMapper.list();
    }

    @Override
    public void delete(Integer id) {
        //调用mapper的删除方法
        deptMapper.delete(id);
    }

    @Override
    public void save(Dept dept) {
        //补充基础属性updateTime和createTime
        dept.setUpdateTime(LocalDateTime.now());
        dept.setCreateTime(LocalDateTime.now());
        //调用mapper的保存方法
        deptMapper.insert(dept);
    }

    @Override
    public Dept getByid(Integer id) {
        //调用mapper的getById方法
        return deptMapper.getById(id);
    }

    @Override
    public void update(Dept dept) {
        //补充基础属性updateTime
        dept.setUpdateTime(LocalDateTime.now());
        //调用mapper的update方法
        deptMapper.update(dept);
    }
}
